package com.family.floor.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.family.floor.controller.vo.InformationAndfloorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.family.floor.entity.InformationEntity;
import com.family.floor.service.InformationService;
import com.family.common.utils.PageUtils;
import com.family.common.utils.R;



/**
 * 
 *
 * @author wen
 * @email 1023076426@qq.com
 * @date 2021-09-13 18:57:12
 */
@RestController
@RequestMapping("floor/information")
public class InformationController {
    @Autowired
    private InformationService informationService;

    /**
     * 资讯详情
     * id 资讯id
     */
    @RequestMapping("detail/{id}")
    public R informationDetail(@PathVariable("id")Integer id){
        InformationAndfloorVo informationAndfloorVo=informationService.informationDetail(id);
        return R.ok().put("data",informationAndfloorVo);
    }


    /**
     * 首页最新资讯
     * @return
     */
    @RequestMapping("/lastInformation")
    public R lastInformation(){
        InformationEntity lastInfomation=informationService.lastInformation();
        return R.ok().put("data",lastInfomation);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = informationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{infoId}")
    public R info(@PathVariable("infoId") Integer infoId){
		InformationEntity information = informationService.getById(infoId);

        return R.ok().put("information", information);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody InformationEntity information){
		informationService.save(information);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody InformationEntity information){
		informationService.updateById(information);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] infoIds){
		informationService.removeByIds(Arrays.asList(infoIds));

        return R.ok();
    }

}
